package yawning.mew.cat;

import yawning.mew.BuffsDebuffs.Buff;
import yawning.mew.sim.SimulationAction;
import yawning.mew.sim.SimulationEventAction;

public class EventUnholyFrenzy extends SimulationEventAction {
	CatModelSimState mState;
	double mCooldownExpireTime;

	EventUnholyFrenzy(CatModelSimState state) {
		super(state.mSimEngine);
		mState = state;

		if (!mState.mModel.buffsDebuffs.isBuff(Buff.UNHOLYFRENZY)) mCooldownExpireTime = Double.MAX_VALUE;
	}

	@Override
	public double perform() {
		if (mCooldownExpireTime <= mState.mSimEngine.getSimTime() && mState.mModel.buffsDebuffs.isBuff(Buff.UNHOLYFRENZY)) {
			schedule(mState.mModel.unholyFrenzyBuffDuration);
			mState.mModel.multiplyHaste(mState.mModel.buffUnholyFrenzy);
			mCooldownExpireTime = mState.mSimEngine.getSimTime() + mState.mModel.unholyFrenzyCDDuration;

			if (mState.mIsLogging) mState.mLog.log("Unholy Frenzy\n");

			return 0.0;
		}
		return SimulationAction.ACTION_FAIL;
	}

	@Override
	public void onExpire() {
		if (mState.mIsLogging) mState.mLog.log("Unholy Frenzy: Expiration\n");

		mState.mModel.multiplyHaste(1.0 / mState.mModel.buffUnholyFrenzy);
	}
}